#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

my $vl;
my $vl2;
my $match0 = "^ VLAN";
my $match1 = "^ Interface";
my $match2 = "the root";
my $match3 = "ed root";
my $match4 = "ed bridge";
my $match5 = "ed port";
my $match6 = "^ Port";
my $match7 = "rt path cost";
my $string;
my $count = 0;
my $data_file = "shspanningtreedetail.txt";
#print "$data_file \n";

open (DATA, "$data_file") or die "can't open $data_file $!";
my @array_of_data = <DATA>;
chomp @array_of_data;
foreach $vl(@array_of_data)
{
if ($vl =~ m/($match0\d\+)/)
{
print "$vl\n";
}
elsif ($vl =~ m/(($match1)|($match6))/)
{
print "\n###### Begin Interface Specific Information #######\n";
my @intsplit = split(/\)/,$vl);
my $intsplit;
my $intsplitspec1;
my $intsplitspec2;
foreach $intsplit(@intsplit){
if ($intsplit =~ m/(Inter)|(Port)/){
my @intsplitspec1 = split(/\(/,$intsplit);
for ($count=0; $count <= 1; $count++){
@intsplitspec1[0] =~ s/[^\d?.]//g;
print "My Port and interface info is @intsplitspec1[$count]\n";
}
}
elsif ($intsplit =~ m/VLAN/){
my @intsplitspec2 = split(/is/,$intsplit);
foreach $intsplitspec2(@intsplitspec2){
if ($intsplitspec2 =~ m/VLAN\d\d\d\d/){
#$intsplitspec2 = substr($intsplitspec2, 4, 9);
print "Interface: $intsplitspec2\n";
}else{
$intsplitspec2 = substr($intsplitspec2, 1, 25);
print "Interface: $intsplitspec2\n";
}
}
}
}
}
elsif ($vl =~ m/($match7)/)
{
my @intpcoprisplit = split(/,/,$vl);
my $intpcoprisplit;
foreach $intpcoprisplit(@intpcoprisplit){
if ($intpcoprisplit =~ m/priority/){
$intpcoprisplit =~ s/\D//g;
print "this port priority: $intpcoprisplit\n";
}elsif ($intpcoprisplit =~ m/cost/){
$intpcoprisplit =~ s/\D//g;
print "this port cost: $intpcoprisplit\n";
}elsif ($intpcoprisplit =~ m/ident/){
$intpcoprisplit =~ s/\D//g;
print "this port id: $intpcoprisplit\n";
}
}
}
elsif ($vl =~ m/($match2)/)
{
print "Are we the root?: $vl\n\n";
}
elsif ($vl =~ m/($match3)/)
{
print "\n###### Begin Designated Root Information #######\n\n";
my @rosplit = split(/,/,$vl);
my $rosplit;
foreach $rosplit(@rosplit){
if ($rosplit =~ m/priority/){
$rosplit =~ s/\D//g;
print "priority: $rosplit\n";
}elsif ($rosplit =~ m/address/){
$rosplit = substr($rosplit, 9, 14);
print "address: $rosplit\n";
}
}
}
elsif ($vl =~ m/($match4)/)
{
print "\n###### Begin Designated Bridge Information #######\n\n";
my @dbsplit = split(/,/,$vl);
my $dbsplit;
foreach $dbsplit(@dbsplit){
if ($dbsplit =~ m/priority/){
$dbsplit =~ s/\D//g;
print "priority: $dbsplit\n";
}elsif ($dbsplit =~ m/address/){
$dbsplit = substr($dbsplit, 9, 14);
print "address: $dbsplit\n";
}
}

}
elsif ($vl =~ m/($match5)/)
{
print "\n###### Begin Designated Bridge Port/Cost Information #######\n\n";
my @dbpcsplit = split(/,/,$vl);
my $dbpcsplit;
foreach $dbpcsplit(@dbpcsplit){
if ($dbpcsplit =~ m/port/){
$dbpcsplit =~ s/[^\d?.]//g;
print "des port num: $dbpcsplit\n";
}elsif ($dbpcsplit =~ m/cost/){
$dbpcsplit =~ s/\D//g;
print "des path cost: $dbpcsplit\n";
}
}
print "\n###### End Interface Specific Information #######\n";
}
       # $vl =~ /($match1\d\d\d\d)\s($match2)\s($match3)/;
	#print "vlan: $1\n";
	#print "interface: $2\n";
	#print "port: $3\n";
}


close (DATA);
